package com.ruoyi.energy.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.energy.domain.NyTransCheck;
import com.ruoyi.energy.domain.NyTransLoad;
import com.ruoyi.energy.domain.vo.WXNyTransDetial;
import com.ruoyi.energy.service.INyTransCheckService;
import com.ruoyi.energy.service.INyTransLoadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 变压器监测Controller
 *
 * @author cjie
 * @date 2021-10-11
 */
@Api(tags = " 变压器监测")
@RestController
@RequestMapping("/nyTransCheck")
public class NyTransCheckController extends BaseController {
    @Autowired
    private INyTransCheckService nyTransCheckService;
    @Autowired
    private INyTransLoadService nyTransLoadService;
    /**
     * 查询变压器监测列表
     */
    @ApiOperation(value="查询变压器监测列表", notes="查询变压器监测列表")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:list")
    @GetMapping("/list")
    public TableDataInfo list(NyTransCheck nyTransCheck) {
        startPage();
        List<NyTransCheck> list = nyTransCheckService.selectNyTransCheckList(nyTransCheck);

        return getDataTable(list);
    }

    /**
     * 导出变压器监测列表
     */
    @ApiOperation(value="导出变压器监测列表", notes="导出变压器监测列表")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:export")
    @Log(title = "变压器监测", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NyTransCheck nyTransCheck) throws IOException {
        List<NyTransCheck> list = nyTransCheckService.selectNyTransCheckList(nyTransCheck);
        ExcelUtil<NyTransCheck> util = new ExcelUtil<NyTransCheck>(NyTransCheck.class);
        util.exportExcel(response, list, "变压器监测数据");
    }
    /**
     * 获取变压器监测详细信息
     */
    @ApiOperation(value="获取变压器监测详细信息", notes="获取变压器监测详细信息")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(nyTransCheckService.selectNyTransCheckById(id));
    }

    @ApiOperation(value="箱变-设备监测抄录", notes="箱变-设备监测抄录")
    @PreAuthorize(hasPermi = "energy:nyTrans:query")
    @GetMapping(value = "/wx/gen/{id}")
    public AjaxResult genWXCheckInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(nyTransCheckService.genWXCheckInfo(id));
    }

    @ApiOperation(value="箱变-设备监测提交", notes="箱变-设备监测提交")
    @PostMapping(value = "/wx/save")
    public AjaxResult saveWXCheckInfo(@RequestBody WXNyTransDetial wxNyTransDetial) {
        return toAjax(nyTransCheckService.saveWXNyTransCheck(wxNyTransDetial));
    }

    @ApiOperation(value="箱变-设备监测-月-总负荷", notes="箱变-设备监测-月-总负荷")
    @PreAuthorize(hasPermi = "energy:nyTrans:query")
    @Log(title = "历史负荷")
    @GetMapping(value = "/wx/month")
    public TableDataInfo getTransCheckInfo(NyTransLoad nyTransLoad) {
        List<NyTransLoad> list = nyTransLoadService.selectNyTransLoadList(nyTransLoad);
        return getDataTable(list);
    }

    @ApiOperation(value="箱变-设备监测-天-企业负荷", notes="箱变-设备监测-天-企业负荷")
    @Log(title = "企业负荷")
    @GetMapping(value = "/wx/list")
    public TableDataInfo getTransCheckInfo1(NyTransCheck nyTransCheck) {
        List<NyTransCheck> list = nyTransCheckService.selectNyTransCheckList(nyTransCheck);
        return getDataTable(list);
    }
    /**
     * 新增变压器监测
     */
    @ApiOperation(value="新增变压器监测", notes="新增变压器监测")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:add")
    @Log(title = "变压器监测", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NyTransCheck nyTransCheck) {
        return toAjax(nyTransCheckService.insertNyTransCheck(nyTransCheck));
    }

    /**
     * 修改变压器监测
     */
    @ApiOperation(value="修改变压器监测", notes="修改变压器监测")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:edit")
    @Log(title = "变压器监测", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NyTransCheck nyTransCheck) {
        return toAjax(nyTransCheckService.updateNyTransCheck(nyTransCheck));
    }

    /**
     * 删除变压器监测
     */
    @ApiOperation(value="删除变压器监测", notes="删除变压器监测")
    @ApiImplicitParam(name = "ids", value = "变压器监测ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "energy:nyTransCheck:remove")
    @Log(title = "变压器监测", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(nyTransCheckService.deleteNyTransCheckByIds(ids));
    }

}
